#ifndef STX_ALGORITHM_ADJACENT_FIND_HPP_
#define STX_ALGORITHM_ADJACENT_FIND_HPP_

#include <stx/algorithm/common.hpp>

namespace stx {

template <class ForwardIterator, class BinaryPredicate>
inline ForwardIterator
adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred)
{
    if (first != last) {
        ForwardIterator i = first;
        while (++i != last) {
            if (pred(*first, *i)) {
                return first;
            }
            first = i;
        }
    }
    return last;
}

template <class ForwardIterator>
inline ForwardIterator
adjacent_find(ForwardIterator first, ForwardIterator last)
{
    typedef typename std::iterator_traits<ForwardIterator>::value_type v;
    return stx::adjacent_find(first, last, equal_to<v>());
}

} // namespace stx

#endif // STX_ALGORITHM_ADJACENT_FIND_HPP_
